<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{$lang.title}</title>
    <include file="common/tag"/>
</head>
<body>
<div style=" margin: 30px;">

    <include file="common/search"/>

    <table class="layui-hide" id="datatable" lay-filter="datatable" lay-size="sm" lay-skin="row"></table>

</div>
</body>
</html>
<include file="common/js"/>
<script>

    $(function(){
        layui.use(['table','laydate'], function(){
            let table = layui.table;
            let laydate = layui.laydate;

            //渲染range时间控件
            $.each($('.search_date_range'),function (k) {
                let id = $(this).attr('id');
                laydate.render({
                    elem: '#'+id
                    ,format: 'yyyy-MM-dd'
                    ,value: $("#"+id).val()
                    ,range: true
                    ,trigger:'click'
                });
            });
            //渲染单天时间控件
            $.each($('.search_date'),function (k) {
                let id = $(this).attr('id');
                laydate.render({
                    elem: '#'+id
                    ,value: $("#"+id).val()
                    ,range: false
                    ,trigger:'click'
                });
            });

            table.render({
                elem: '#datatable'
                ,url:'{$__url}'
                ,method: 'POST'
                ,toolbar: '#toolbar'
                ,cellMinWidth: 80
                ,even: true
                ,size: 'lg'
                ,id: 'datatable'
                ,where: postSearchData()
                ,parseData: function(resp){ //res 即为原始返回的数据
                    if(resp.code==302){
                        layer.msg("{$lang.token_exceed}");
                        parent.location.reload();
                        return;
                    }
                    return {
                        "code": resp.code,
                        "msg": resp.msg,
                        "count": resp.count,
                        "data": resp.data,
                    };
                }
                ,cols: [{$__header}]
                ,page: true
            });

            let active = {
                reload: function(){
                    //执行重载
                    table.reload('datatable', {
                        page: {
                            curr: $(".layui-laypage-em").next().html()
                        }
                        ,where: postSearchData()
                    }, 'data');
                }
            };

            $('.data-search .layui-btn').on('click', function(){
                let type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

        });

    });

</script>